<template>
	<view>
		<u-sticky bgcolor="#fafafa">
			
			<view class="" style="background-color: #FAFafa;">
				<view class="flexbetween">
					<view class="shijianbtn margin_right3" @click="shows=true">{{start_time || "开始时间"}}</view>
					<view class="xian margin_right3"></view>
					<view class="shijianbtn" @click="showss=true">{{end_time || "结束时间"}}</view>
				</view>
			</view>
			<u-tabs :list="list1" lineColor="#3478f5" @click="changetab" ></u-tabs>
		</u-sticky>
		<view class="flexcenter" v-if="!list.data.length" >
			<view class="placeholderimage" style="margin-top: 100rpx;"></view>
		</view>
		<view class="mainpadding2">
			<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id" @click="dati()">
				<view class="hei_text bold titletext">{{item.tm_title}}</view>
				<!-- <view class="hei_text bold titletext">{{item.tminfo.title}}</view> -->
				<view class="flexleft margin_top">
					<image :src="userInfo.avatar_text?userInfo.avatar_text:'@static/logo.png'" class="headimg radius" mode=""></image>
					<view class="flexcolumnbet margin_left2" style="height: 120rpx; width: 100%;" >
						<view class="flexbetween" style="width: 100%;">
							<view class="xiaolan">{{userInfo.nickname}}</view>
							<!-- :0=已完成,1=不符合要求,2=配额已满.3=重复答题,4=错误定位,5=答题过快,6=项目暂停,7=项目关闭,8=非法回调 -->
							<view class="lan_text main_size bold" v-if="item.status==0">已完成</view>
							<view class="hong_text main_size bold" v-else>
								<text v-show="item.status==1">不符合要求</text>
								<text v-show="item.status==2">配额已满</text>
								<text v-show="item.status==3">重复答题</text>
								<text v-show="item.status==4">错误定位</text>
								<text v-show="item.status==5">答题过快</text>
								<text v-show="item.status==6">项目暂停</text>
								<text v-show="item.status==7">项目关闭</text>
								<text v-show="item.status==8">非法回调</text>
							</view>
						</view>
						<view class="xiaohui">编号：{{item.tsurveyId}}</view>
						<!-- <view class="xiaohui">编号：{{item.tminfo.tsurveyId}}</view> -->
						<view class="flexbetween" style="width: 100%;">
							<view class="xiaohui">{{item.createtime_text}}</view>
							<view class="mian_size hong_text bold">{{item.score}}</view>
						</view>
					</view>
				</view>
				<view class="xiaohui margin_top bold main_size">被分享人:{{item.user.phone}}</view>
			</view>
		</view>
		<u-datetime-picker :show="shows" title="开始时间" v-model="value1" mode="date" @confirm="confirm" @cancel="shows = false"
			closeOnClickOverlay :minDate="0" @close="shows=false"></u-datetime-picker>
		<u-datetime-picker :show="showss" title="结束时间" v-model="value2" mode="date" @confirm="confirms" @cancel="showss = false"
			:minDate="mintime" closeOnClickOverlay @close="showss=false"></u-datetime-picker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				start_time:"",
				end_time:"",
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				userInfo: {},
				shows: false,
				showss: false,
				value1: Number(new Date()),
				value2: Number(new Date()),
				mintime: Number(new Date()),
				list1:[],
				tabsitem:''
			}
		},
		onLoad(){
			this.tmRecordTab()
			this.getInfo()
		},
		methods: {
			tmRecordTab(){
				httpRequest.request('/api/user/tmRecordTab', 'GET', {}).then(res => {
					let arr=[]
					res.data.forEach(item=>{
						arr.push({name:item})
					})
					this.list1 = arr
					this.tabsitem = res.data[0]
					this.init()
				})
			},
			changetab(e){
				this.tabsitem = e.name
				this.init()
			},
			confirm(e) {
				console.log(e);
				this.shows = false;
				this.end_time = '';
				this.mintime = e.value;
				this.start_time = httpRequest.returnDate(e.value);
				this.init()
			},
			confirms(e) {
				this.showss = false;
				this.end_time = httpRequest.returnDate(e.value);
				this.init()
			},
			getInfo(){
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
				})
			},
			init(isPage, page) {
				let _this = this;
				httpRequest.request('/api/user/tmRecordIndex', 'GET', {
					page: page || 1,
					limit: _this.limit,
					start_time: this.start_time,
					end_time: this.end_time,
					title:this.tabsitem
				}, false, false, true).then(res => {
					uni.stopPullDownRefresh()
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			jumpurl(url) {
				uni.navigateTo({
					url
				})
			},
		}
	}
</script>

<style scoped>
	.xian {
		width: 22rpx;
		height: 0rpx;
		background-color: #999999;
		border: 1rpx solid #999999;
	}
	.shijianbtn {
		padding: 20rpx 65rpx;
		background: #F7F9FA;
		border-radius: 41rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}
</style>